 
<?php $user = $this->user->get();
$condition ="";

if($this->user->is_role(3))
{

	$condition = " and  users.user_id =".$user["user_id"];
}


$sql ="SELECT 
	    lpad(material_requests.mr_id, 5,'0') AS `code`,
		material_requests.detail, 
		material_requests.place_id, 
		material_requests.user_id, 
		date_format(material_requests.create_date,'%d/%m/%Y') as create_date, 
		users.firstname, 
		users.lastname, 
		users.position, 
		place.place_name,
		mr_id
	FROM material_requests INNER JOIN users ON material_requests.user_id = users.user_id
		 INNER JOIN place ON material_requests.place_id = place.place_id where  mr_id =  $id $condition";

$rows = $this->db->query($sql)->result_array();
$row = $rows[0];
//print_r($rows);
?>
<table class="list" cellpadding="0" >
<tr>
<th style="width: 120px;" >เลขที่สำรวจ</th>
<th><?php echo $row['code'];  ?></th>
</tr>
<tr>
<td class="tdlabel">วันที่สำรวจ</td>
<td><?php echo $row['create_date'];  ?></td>
</tr>
<tr>
<td class="tdlabel">ชื่อ-นามสกุล</td>
<td><?php echo $row['firstname']." ".$row["lastname"];  ?></td>
</tr>

<tr>
	<td class="tdlabel">รายละเอียด/หมายเหตุ</td>
	<td><?php echo $row['detail'];  ?></td>
</tr>
<tr>
	<td class="tdlabel">ห้องปฎิบัติการ/สถานที่</td>
	<td><?php echo $row['place_name'];  ?></td>
</tr>
</table>
รายการผลสำรวจดังนี้
  <?php 
$rows = $this->db->query("select * from meterial_base_categories order by sort_order asc")->result_array();
foreach($rows as $base){
$sql ="select * from request_item_views where mr_id = '".$row["mr_id"]."' and cat_base_id = ".$base['cat_base_id'] ;
$cats =  $this->db->query($sql)->result_array(); ?>

<table class="list" >
          <tbody><tr class=" odd">
            <th style="width:200px;" ><?php echo $base["cat_base_name"]; ?></th>
            
           
             <th style="width:100px;">ความต้องการเพิ่มเติม</th>
              <th style="width:200px;">รายละเอียด</th>
          </tr>
         <?php
          $i = 1;
          foreach($cats as $row){ ?>
        
          <tr class="<?php if($i++%2){ echo "even";} ?>" >
            
            
            <td><?php echo $row['category_name']; ?></td>
            
            <td><?php echo $row['amount']; ?></td>
            <td><?php echo $row['detail']; ?></td>
            
          </tr>
          <?php } } ?>
        </tbody></table>

